<?php
use yii\helpers\Url;
use yii\bootstrap\ActiveForm;
$this->context->layout = false;
//使用率
echo $this->render("@app/views/public/useRate.php")
?>
<head>
    <link rel="stylesheet" href="/web/css/kendo/kendo.mobile.all.min.css" type="text/css"/>
    <link rel="stylesheet" href="/web/css/kendo/kendo.blueopal.mobile.min.css" type="text/css"/>
    <style>
        .km-switch-label-on{
            background-color: #13688c !important;
            left: -178%!important;
        }
        .km-switch-on > span > span {
            transform: translateX(33px) translateY(0px)!important;
        }
        .km-switch-label-off, .km-switch-label-on {
            line-height: 1.87em!important;
        }
        .km-widget{
            border-radius: 4px;
        }
    </style>
</head>
<div id="Summary-list"></div>
<script type="text/x-kendo-template" id="SummaryTemplate">
    <a class="k-button k-button-icontext" onclick="setGroup(1);"><span class="glyphicon glyphicon-list-alt"> 摘错绩效</span></a>
    <a class="k-button k-button-icontext" onclick="setGroup(2);"><span class="glyphicon glyphicon-list-alt"> 五大类</span></a>
    <a class="k-button k-button-icontext" onclick="setGroup(3);"><span class="glyphicon glyphicon-list-alt"> LEVEL 1/2</span></a>
    <a class="k-button k-button-icontext" onclick="setGroup(4);"><span class="glyphicon glyphicon-list-alt"> 人員</span></a>
    <a class="k-button k-button-icontext" onclick="setGroup(5);"><span class="glyphicon glyphicon-list-alt"> 影响晋升</span></a>
    <?php if($date['management']){?>
    <input type="checkbox" id="management"  name="management">
    <?php }?>
    <input type="text" id="su_date_start"  name="su_date_start" value="<?=$date['su_date_start']?>" placeholder="开始月份">
    <input type="text" id="su_date_end"  name="su_date_end" value="<?=$date['su_date_end']?>" placeholder="结束月份">
    <a class="k-button k-button-icontext" onclick="setGroup(0);" style="float:right "><span>清除</span></a>
    <a class="k-button k-button-icontext k-grid-excel" style="float:right"><span class="k-icon k-i-excel"></span>导出列表</a>
</script>
<script>
    $(document).ready(function() {
        var management = false;
        $("#Summary-list").kendoGrid({
            dataSource: {
                transport: {
                    read: function (e){
                        $.ajax({
                            data:{
                                'su_date_start':$("#su_date_start").val(),
                                'su_date_end':$("#su_date_end").val(),
                                'management':management
                            },
                            url: "<?=Url::to(['getsummarylist']); ?>",
                            type: 'GET',
                            dataType: 'JSON',
                            success: function (res) {
                                e.success(res);
                            }
                        })
                    }
                },
                schema: {
                    model: {
                        fields: {
                        }
                    }
                },
                group:[
//                    {field: "created", aggregates: [ { field: "created", aggregate: "count" }]},
                    {field: "column_name", aggregates: [ { field: "column_name", aggregate: "count" ,collapse:true}]},
                    {field: "department_name", aggregates: [ { field: "department_name", aggregate: "count" }]},
                    {field: "group_name", aggregates: [ { field: "group_name", aggregate: "count" }]},
                    {field: "type_name", aggregates: [ { field: "type_name", aggregate: "count" }]},
                    {field: "level1_name", aggregates: [ { field: "level1_name", aggregate: "count" }]},
                    {field: "level2_name", aggregates: [ { field: "level2_name", aggregate: "count" }]}
                ]
            },
            filterable: {
                extra: false,
                operators: {
                    string: {
                        contains: "包含",
                        doesnotcontain: "不包含",
                        eq: "等于",
                        neq: "不等于"
                    }
                }
            },
            sortable: true,
            reorderable: true,
            groupable: true,
            resizable: true,
            toolbar:kendo.template($("#SummaryTemplate").html()),
            excel: {
                allPages: true,
                fileName:"汇总.xlsx",
                filterable: true
            },
            excelExport: function(e) {},
            columns: [
                {
                    field:"created",
                    title:"发布时间",
//                    aggregates:["count"],
//                    groupHeaderTemplate: "#= value # (总量: #= count#)",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute,
                    width:"8%"
                },
                {
                    field:"column_name",
                    title:"三类别",
                    aggregates:["count"],
                    groupHeaderTemplate: "#= value # (总量: #= count#)",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field:"department_name",
                    title:"部门",
                    aggregates:["count"],
                    groupHeaderTemplate: "#= value # (总量: #= count#)",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field:"group_name",
                    title:"组别",
                    aggregates:["count"],
                    groupHeaderTemplate: "#= value # (总量: #= count#)",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "type_name",
                    title:"五大类" ,
                    aggregates:["count"],
                    groupHeaderTemplate: "#= value # (总量: #= count#)",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "level1_name",
                    title:"LEVEL1",
                    aggregates:["count"],
                    groupHeaderTemplate: "#= value # (总量: #= count#)",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field:"level2_name",
                    title: "LEVEL2",
                    aggregates:["count"],
                    groupHeaderTemplate: "#= value # (总量: #= count#)",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "name_en_long",
                    title:"英文名" ,
                    aggregates:["count"],
                    groupHeaderTemplate: "#= value # (总量: #= count#)",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field:"content",
                    title:"详情",
                    width:"40%"

                },
                {
                    field: "tag",
                    title:"警告信" ,
                    aggregates:["count"],
                    groupHeaderTemplate: "#= value # (总量: #= count#)",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
                {
                    field: "rating",
                    title:"评级" ,
                    aggregates:["count"],
                    groupHeaderTemplate: "#= value # (总量: #= count#)",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                }
            ],
            dataBound: function () {
                dataView = this.dataSource.view();
                    for (var i = 0; i < dataView.length; i++) {
                        if(typeof(dataView[i].uid)=="undefined"){
                            //removeList(dataView[i]);
                        }else{
                            var uid = dataView[i].uid;
                            //$("#Summary-list").find("[data-uid='" + uid + "']").remove();
                        }
                    }
                var number = 0;
                $(".k-grouping-row").each(function(index,e){
                    var ee =$(e);
                    if(ee.text().indexOf('null')>=0&&number==0){
                        ee[0].innerHTML=ee[0].innerHTML.replace('null','暫無分類');
                        number = ee.children("td:last-child").attr("colspan");
                        //ee.remove();
                    }else{
                        if(parseInt(number) > parseInt(ee.children("td:last-child").attr("colspan"))){
                            ee[0].innerHTML=ee[0].innerHTML.replace('null','暫無分類');
                            //ee.remove();
                        }else if(parseInt(number) <= parseInt(ee.children("td:last-child").attr("colspan"))){
                            number =0;
                        }
                    }
                });
                var __grid = $("#Summary-list").data("kendoGrid");
                $(".k-grouping-row").each(function (index,el) {
                    __grid.collapseGroup( $(el));//折叠 展开__grid.expandGroup($(el));
                })
            }
        });
        <?php if($date['management']){?>
        $("#management").kendoMobileSwitch({
            onLabel: "管理",
            offLabel: "非管理員",
            change:function (e) {
                management = e.checked;
                var summaryGrid = $("#Summary-list").data("kendoGrid");
                summaryGrid.dataSource.read();
                summaryGrid.refresh();
            },
            open: function () {

            }
        });
        <?php  }?>
        $("#su_date_start").kendoDatePicker({
            format: "yyyy/MM/dd",
            change:function(e){
                var __grid = $("#Summary-list").data("kendoGrid");
                __grid.dataSource.read();
                __grid.refresh();
            }
        });
        $("#su_date_end").kendoDatePicker({
            format: "yyyy/MM/dd",
            change:function(e){
                var __grid = $("#Summary-list").data("kendoGrid");
                __grid.dataSource.read();
                __grid.refresh();
            }
        });
    });
    function removeList(obj){
        for(var s = 0; s <obj.items.length;s++){
            if(typeof(obj.items[s].uid) == "undefined"){
                removeList(obj.items[s]);
            }else{
                var uid = obj.items[s].uid;
                $("#Summary-list").find("[data-uid='" + uid + "']").remove();
            }
        }
    }
    function setGroup(state){
        var sdaf = $("#Summary-list").data("kendoGrid");
        if(state==2){
            sdaf.dataSource.group([
                    {field: "type_name", aggregates: [ { field: "type_name", aggregate: "count" }]},
                    {field: "department_name", aggregates: [ { field: "department_name", aggregate: "count" }]},
                    {field: "group_name", aggregates: [ { field: "group_name", aggregate: "count" }]},
                    {field: "level1_name", aggregates: [ { field: "level1_name", aggregate: "count" }]},
                    {field: "level2_name", aggregates: [ { field: "level2_name", aggregate: "count" }]}
                ]);
        }else if(state ==3){
            sdaf.dataSource.group([
                {field: "department_name", aggregates: [ { field: "department_name", aggregate: "count" }]},
                {field: "level1_name", aggregates: [ { field: "level1_name", aggregate: "count" }]},
                {field: "level2_name", aggregates: [ { field: "level2_name", aggregate: "count" }]}
            ]);
        }else if (state ==4){
            sdaf.dataSource.group([
                {field: "department_name", aggregates: [ { field: "department_name", aggregate: "count" }]},
                {field: "group_name", aggregates: [ { field: "group_name", aggregate: "count" }]},
                {field: "name_en_long", aggregates: [ { field: "name_en_long", aggregate: "count" }]},
                {field: "column_name", aggregates: [ { field: "column_name", aggregate: "count" }]},
                {field: "level1_name", aggregates: [ { field: "level1_name", aggregate: "count" }]},
                {field: "level2_name", aggregates: [ { field: "level2_name", aggregate: "count" }]}
            ]);
        }else if(state ==1){
            sdaf.dataSource.query([
                {filter:{
                    logic:"and",
                    filters:[{
                        field:"column_name",
                        value:"绩效",
                        operator:"eq"
                    }]
                }}
            ]);
            sdaf.dataSource.group([
                {field: "column_name", aggregates: [ { field: "column_name", aggregate: "count" }]},
                {field: "department_name", aggregates: [ { field: "department_name", aggregate: "count" }]},
                {field: "group_name", aggregates: [ { field: "group_name", aggregate: "count" }]},
                {field: "type_name", aggregates: [ { field: "type_name", aggregate: "count" }]},
                {field: "level1_name", aggregates: [ { field: "level1_name", aggregate: "count" }]},
                {field: "level2_name", aggregates: [ { field: "level2_name", aggregate: "count" }]}
            ]);
        }else if(state ==0){
            sdaf.dataSource.group([]);
        }else if(state ==5) {
            sdaf.dataSource.group([
                {field: "department_name", aggregates: [ { field: "department_name", aggregate: "count" }]},
                {field: "tag", aggregates: [ { field: "tag", aggregate: "count" }]},
                {field: "rating", aggregates: [ { field: "rating", aggregate: "count" }]},
                {field: "group_name", aggregates: [ { field: "group_name", aggregate: "count" }]},
                {field: "name_en_long", aggregates: [ { field: "name_en_long", aggregate: "count" }]}
            ]);
        }

    }
</script>

